package com.xzy.repository;

import com.xzy.entity.StudentEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.SelectKey;

import java.util.List;

/**
 * 学生表
 *
 * @author xzy.xiao
 * @date 2022/4/1  10:50
 */
@Mapper
public interface StudentMapper {

    /**
     * 新增并获得ID —— 通过SelectKey标签或注解
     *
     * @param studentEntity 学生信息
     */
    @SelectKey(statement = "select LAST_INSERT_ID()", resultType = Long.class, keyColumn = "student_id", keyProperty = "studentId", before = false)
    @Insert("insert into tbl_student(student_id,student_name) values (#{studentId},#{studentName})")
    void saveAndGetId0(StudentEntity studentEntity);

    void saveAndGetId1(StudentEntity studentEntity);

    /**
     * 新增并获得ID —— 通过Insert标签或注解
     *
     * @param studentEntity -
     */
    @Options(useGeneratedKeys = true, keyColumn = "student_id", keyProperty = "studentId")
    @Insert("insert into tbl_student(student_id,student_name) values (#{studentId},#{studentName})")
    void saveAndGetId2(StudentEntity studentEntity);

    void saveAndGetId3(StudentEntity studentEntity);

    /**
     * 批量新增并获得ID
     */
    void saveAllAndGetIds(List<StudentEntity> studentEntities);
}
